home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 30.1 KB | 1,037 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPart.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWPART_K
- #include "FWPart.k"
- #endif
-
- #ifndef FWCONTNT_H
- #include "FWContnt.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWIDLE_H
- #include "FWIdle.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWINTER_H
- #include "FWInter.h"
- #endif
-
- #ifndef FWPRTITE_H
- #include "FWPrtIte.h"
- #endif
-
- #ifndef FWLNKMGR_H
- #include "FWLnkMgr.h"
- #endif
-
- #ifndef FWCMD_H
- #include "FWCmd.h"
- #endif
-
- #ifndef FWMNUBAR_H
- #include "FWMnuBar.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWEVENTD_H
- #include "FWEventD.h"
- #endif
-
- #ifndef SLMIXOS_H
- #include "SLMixOS.h"
- #endif
-
- #ifndef FWSEMINT_H
- #include "FWSemInt.h"
- #endif
-
- #ifndef SLODFSTR_K
- #include "SLODFStr.k"
- #endif
-
- #ifndef SLODFSTR_H
- #include "SLODFStr.h"
- #endif
-
- #ifndef _STDTYPIO_
- #include "StdTypIO.h"
- #endif
-
- // ----- OS Utilites -----
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWRESSIN_H
- #include "FWResSin.h"
- #endif
-
- // ----- OpenDoc Utilites -----
-
- #ifndef _INFOUTIL_
- #include "InfoUtil.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Foci_defined
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- //========================================================================================
- // Globals
- //========================================================================================
-
- unsigned short FW_CPart::gSessionGlobalsCount = 0;
-
- ODTypeToken FW_CPart::gSelectionFocusToken = 0;
- ODTypeToken FW_CPart::gMenuFocusToken = 0;
- ODTypeToken FW_CPart::gKeyFocusToken = 0;
- ODTypeToken FW_CPart::gModalFocusToken = 0;
- ODTypeToken FW_CPart::gClipboardFocusToken = 0;
- ODTypeToken FW_CPart::gScrollingFocusToken = 0;
- ODTypeToken FW_CPart::gViewAsFrameToken = 0;
- ODTypeToken FW_CPart::gViewAsSmallIconToken = 0;
- ODTypeToken FW_CPart::gViewAsLargeIconToken = 0;
- ODTypeToken FW_CPart::gViewAsThumbnailToken = 0;
-
- #ifdef FW_BUILD_MAC
- ODType FW_CPart::gMacPICTDataType = NULL;
- ODType FW_CPart::gMacPICTFileType = NULL;
- ODType FW_CPart::gMachfsDataType = NULL;
- ODType FW_CPart::gMacTEXTFileType = NULL;
- ODType FW_CPart::gMacTEXTDataType = NULL;
- ODType FW_CPart::gMacMooVFileType = NULL;
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwpart2
- #endif
-
- FW_DEFINE_CLASS_M1(FW_CPart, FW_MEventHandler)
- FW_DEFINE_AUTO(FW_CPart)
-
- //========================================================================================
- // class FW_CPart
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::FW_CPart
- //----------------------------------------------------------------------------------------
-
- FW_CPart::FW_CPart(ODPart* odPart,
- FW_Instance partInstance,
- FW_ResourceId partInfoID) :
- FW_MEventHandler(),
- fODPart(odPart),
- fMenuBar(NULL),
- fEventDispatcher(NULL),
- fLastActiveFrame(NULL),
- fPresentations(NULL),
- fDefaultPresentation(NULL),
- fIdleCount(0),
- fModalDialogCount(0),
- fExtensionManager(NULL),
- fSemanticInterface(NULL),
- fPartInstance(partInstance),
- fViewAsIconID(0),
- fLinkManager(NULL),
- fPrintInfo(NULL),
- fIdler(NULL),
- fContent(NULL),
- fDataInterchange(NULL),
- fPartInfoID(partInfoID),
- fPartKind(NULL)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::~FW_CPart
- //----------------------------------------------------------------------------------------
-
- FW_CPart::~FW_CPart()
- {
- FW_START_DESTRUCTOR
- FW_ASSERT(fIdleCount == 0);
- FW_ASSERT(fModalDialogCount == 0);
-
- FW_ASSERT(fIdler == NULL); // Should be NULL by now
-
- // ----- Delete all the presentations
- FW_CPresentation* presentation;
- while ((presentation = (FW_CPresentation*)fPresentations->First()) != NULL)
- {
- PrivRemovePresentation(presentation);
- delete presentation;
- }
-
- delete fPresentations;
- fPresentations = NULL;
-
- // ----- Delete MenuBar
- delete fMenuBar;
- fMenuBar = NULL;
-
- // ----- Delete Event Dispatcher
- delete fEventDispatcher;
- fEventDispatcher = NULL;
-
- // ----- Delete Semantic Interface
- delete fSemanticInterface;
- fSemanticInterface = NULL;
-
- // ----- Delete Link Manager
- delete fLinkManager;
- fLinkManager = NULL;
-
- // ----- Delete Content
- delete fContent;
- fContent = NULL;
-
- // ----- Delete Data Interchange
- delete fDataInterchange;
- fDataInterchange = NULL;
-
- // ----- Release All the globals
- PrivReleaseGlobals();
-
- // ----- Delete Part kind -----
- if (fPartKind)
- FW_PrimitiveFreeBlock(fPartKind);
- fPartKind = NULL;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::Initialize
- //---------------------------------------------------------------------------------------
- // Call inherited first when overriding
-
- void FW_CPart::Initialize(Environment *ev)
- {
- PrivInitGlobals(ev);
-
- // ----- Menu bar -----
- fMenuBar = new FW_CMenuBar(ev, fODPart, fPartInstance);
-
- // ----- Create Event Dispatcher -----
- fEventDispatcher = this->PrivNewEventDispatcher(ev);
-
- // ----- Presentation collection -----
- fPresentations = FW_NEW(FW_TOrderedCollection<FW_CPresentation>, ());
-
- // ----- Data Interchage object -----
- fDataInterchange = this->PrivNewDataInterchange(ev);
-
- // ----- Part Content object -----
- fContent = this->NewPartContent(ev);
-
- // ----- Linking Support -----
- fLinkManager = this->NewLinkManager(ev);
-
- // ----- Load Part Info Resource -----
- FW_CSharedLibraryResourceFile resFile(ev, fPartInstance);
- #ifdef FW_DEBUG
- if (!resFile->HasResource(ev, fPartInfoID, FW_kPartInfoResourceType))
- FW_DEBUG_MESSAGE("The part info resource is missing");
- #endif
- FW_PResource resource(ev, resFile, fPartInfoID, FW_kPartInfoResourceType);
- FW_PResourceSink sink(ev, resource);
- FW_CReadableStream stream(sink);
- stream >> fViewAsIconID;
- stream >> fPartUserName;
- FW_CString partKind;
- stream >> partKind;
-
- FW_ByteCount byteCount = partKind.GetByteLength();
- fPartKind = (char*)FW_PrimitiveAllocateBlock(byteCount + 1);
- FW_PrimitiveCopyMemory(partKind.RevealBuffer(), fPartKind, byteCount);
- fPartKind[byteCount] = 0;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivInitGlobals
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::PrivInitGlobals(Environment *ev)
- {
- if (gSessionGlobalsCount == 0)
- {
- // ----- Get the session -----
- ODSession* session = GetSession(ev);
-
- FW_ASSERT(gSelectionFocusToken == 0);
- gSelectionFocusToken = session->Tokenize(ev, kODSelectionFocus);
-
- FW_ASSERT(gMenuFocusToken == 0);
- gMenuFocusToken = session->Tokenize(ev, kODMenuFocus);
-
- FW_ASSERT(gKeyFocusToken == 0);
- gKeyFocusToken = session->Tokenize(ev, kODKeyFocus);
-
- FW_ASSERT(gClipboardFocusToken == 0);
- gClipboardFocusToken = session->Tokenize(ev, kODClipboardFocus);
-
- FW_ASSERT(gModalFocusToken == 0);
- gModalFocusToken = session->Tokenize(ev, kODModalFocus);
-
- FW_ASSERT(gScrollingFocusToken == 0);
- gScrollingFocusToken = session->Tokenize(ev, kODScrollingFocus);
-
- FW_ASSERT(gViewAsFrameToken == 0);
- gViewAsFrameToken = session->Tokenize(ev, kODViewAsFrame);
-
- FW_ASSERT(gViewAsSmallIconToken == 0);
- gViewAsSmallIconToken = session->Tokenize(ev, kODViewAsSmallIcon);
-
- FW_ASSERT(gViewAsLargeIconToken == 0);
- gViewAsLargeIconToken = session->Tokenize(ev, kODViewAsLargeIcon);
-
- FW_ASSERT(gViewAsThumbnailToken == 0);
- gViewAsThumbnailToken = session->Tokenize(ev, kODViewAsThumbnail);
-
- #ifdef FW_BUILD_MAC
- ODTranslation *translate = session->GetTranslation(ev);
-
- FW_ASSERT(gMacPICTDataType == NULL);
- gMacPICTDataType = translate->GetISOTypeFromPlatformType(ev, 'PICT', kODPlatformDataType);
-
- FW_ASSERT(gMacPICTFileType == NULL);
- gMacPICTFileType = translate->GetISOTypeFromPlatformType(ev, 'PICT', kODPlatformFileType);
-
- FW_ASSERT(gMachfsDataType == NULL);
- gMachfsDataType = translate->GetISOTypeFromPlatformType(ev, 'hfs ', kODPlatformDataType);
-
- FW_ASSERT(gMacTEXTDataType == NULL);
- gMacTEXTDataType = translate->GetISOTypeFromPlatformType(ev, 'TEXT', kODPlatformDataType);
-
- FW_ASSERT(gMacTEXTFileType == NULL);
- gMacTEXTFileType = translate->GetISOTypeFromPlatformType(ev, 'TEXT', kODPlatformFileType);
-
- FW_ASSERT(gMacMooVFileType == NULL);
- gMacMooVFileType = translate->GetISOTypeFromPlatformType(ev, 'MooV', kODPlatformFileType);
- #endif
- }
-
- gSessionGlobalsCount++;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivReleaseGlobals
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::PrivReleaseGlobals()
- {
- gSessionGlobalsCount--;
- FW_ASSERT(gSessionGlobalsCount >= 0);
-
- if (gSessionGlobalsCount == 0)
- {
- // I am resetting those globals to their default value
- // because if the DLL is not unloaded they wont be reinitialized
- gSelectionFocusToken = 0;
- gMenuFocusToken = 0;
- gKeyFocusToken = 0;
- gClipboardFocusToken = 0;
- gModalFocusToken = 0;
- gScrollingFocusToken = 0;
- gViewAsFrameToken = 0;
- gViewAsSmallIconToken = 0;
- gViewAsLargeIconToken = 0;
- gViewAsThumbnailToken = 0;
-
- #ifdef FW_BUILD_MAC
- FW_ASSERT(gMacPICTDataType != NULL);
- FW_CMemoryManager::FreeBlock(gMacPICTDataType);
- gMacPICTDataType = NULL;
-
- FW_ASSERT(gMacPICTFileType != NULL);
- FW_CMemoryManager::FreeBlock(gMacPICTFileType);
- gMacPICTFileType = NULL;
-
- FW_ASSERT(gMacTEXTDataType != NULL);
- FW_CMemoryManager::FreeBlock(gMacTEXTDataType);
- gMacTEXTDataType = NULL;
-
- FW_ASSERT(gMacTEXTFileType != NULL);
- FW_CMemoryManager::FreeBlock(gMacTEXTFileType);
- gMacTEXTFileType = NULL;
-
- FW_ASSERT(gMacMooVFileType != NULL);
- FW_CMemoryManager::FreeBlock(gMacMooVFileType);
- gMacMooVFileType = NULL;
-
- FW_ASSERT(gMachfsDataType != NULL);
- FW_CMemoryManager::FreeBlock(gMachfsDataType);
- gMachfsDataType = NULL;
- #endif
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::AddProperties
- //---------------------------------------------------------------------------------------
- // AddProperties can be called multiple times
-
- void FW_CPart::AddProperties(Environment* ev, ODStorageUnit* storageUnit)
- {
- // FW_SUAddPropValue correctly tests whether the property and value exist before
- // trying to create them
- FW_SUAddPropValue(ev, storageUnit, kODPropContents, this->GetPartKind(ev));
- }
-
- //------------------------------------------------------------------------------
- // FW_CPart::IsValidContentValue
- //------------------------------------------------------------------------------
- // You need to override this method it your are supporting more than one type.
- // The default implementation only test for the part Kind
-
- FW_Boolean FW_CPart::IsValidContentValue(Environment* ev, ODType type)
- {
- return FW_PrimitiveStringEqual(type, this->GetPartKind(ev));
- }
-
- //------------------------------------------------------------------------------
- // FW_CPart::PrivCleanseContentProperty
- //------------------------------------------------------------------------------
-
- void FW_CPart::PrivCleanseContentProperty(Environment* ev, ODStorageUnit* storageUnit)
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, 0, kODPosAll);
-
- unsigned long numValues = storageUnit->CountValues(ev);
-
- for (unsigned long index = numValues; index >= 1; index--)
- {
- // Index from 1 to n through the values.
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, index, kODPosUndefined);
-
- FW_CAcquireODType valueType = storageUnit->GetType(ev);
-
- if (!IsValidContentValue(ev, valueType))
- storageUnit->Remove(ev);
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::ClearPartStorage
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::ClearPartStorage(Environment* ev, ODStorageUnit* storageUnit)
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, this->GetPartKind(ev), 0, kODPosUndefined);
- storageUnit->Remove(ev);
- storageUnit->AddValue(ev, this->GetPartKind(ev));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivCloneInto
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::PrivCloneInto(Environment* ev,
- ODDraftKey key,
- ODStorageUnit* toSU,
- ODFrame* scope)
- {
- FW_UNUSED(key);
- FW_UNUSED(scope);
-
- // ----- Only thing to do is to externalize my content -----
- ExternalizeContent(ev, toSU, NULL);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::InternalizeContent
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::InternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
- {
- // Simply forward to the content object
- if (fContent)
- fContent->Internalize(ev, storageUnit, FW_kPartStorage, cloneInfo);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::ExternalizeContent
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::ExternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
- {
- if (fContent)
- {
- // By default, clear the part kind value from the storage unit
- this->ClearPartStorage(ev, storageUnit);
-
- // Simply forward to the content object
- fContent->Externalize(ev, storageUnit, FW_kPartStorage, cloneInfo);
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivNewEventDispatcher
- //---------------------------------------------------------------------------------------
-
- FW_CEventDispatcher* FW_CPart::PrivNewEventDispatcher(Environment *ev)
- {
- FW_UNUSED(ev);
-
- return new FW_CEventDispatcher(this, fMenuBar);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::PrivNewPresentation
- //----------------------------------------------------------------------------------------
-
- FW_CPresentation* FW_CPart::PrivNewPresentation(Environment *ev,
- FW_CSelection* selection,
- ODTypeToken presentationType)
- {
- return new FW_CPresentation(ev, this, selection, presentationType);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::RegisterPresentation
- //----------------------------------------------------------------------------------------
- // the selection object will be owned by the presentation
-
- FW_CPresentation* FW_CPart::RegisterPresentation(Environment *ev,
- ODType presentationType,
- FW_Boolean defaultPresentation,
- FW_CSelection* selection)
- {
- FW_CPresentation* presentation = NULL;
- FW_VOLATILE(presentation);
-
- FW_TRY
- {
- ODTypeToken token = this->GetSession(ev)->Tokenize(ev, presentationType);
-
- // ----- Test that we don't register a presentation twice -----
- FW_ASSERT(FindPresentation(ev, token) == NULL);
-
- presentation = PrivNewPresentation(ev, selection, token);
-
- if (selection)
- selection->PrivSetPresentation(presentation);
-
- PrivAddPresentation(presentation);
-
- // ----- if flagged as default or first one -----
- if (defaultPresentation || (fDefaultPresentation == NULL))
- fDefaultPresentation = presentation;
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- if (presentation == NULL)
- delete selection; // Otherwise will be deleted by next line
-
- delete presentation;
-
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- return presentation;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::FindPresentation
- //----------------------------------------------------------------------------------------
-
- FW_CPresentation* FW_CPart::FindPresentation(Environment *ev, ODTypeToken presentationType) const
- {
- FW_CPartPresentationIterator ite(this);
- for (FW_CPresentation* presentation = ite.First(); ite.IsNotComplete(); presentation = ite.Next())
- {
- if (presentation->GetPresentationType(ev) == presentationType)
- return presentation;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::CountDisplayFrame
- //----------------------------------------------------------------------------------------
-
- unsigned long FW_CPart::CountDisplayFrame(Environment *ev) const
- {
- unsigned long count = 0;
-
- FW_CPartPresentationIterator ite(this);
- for (FW_CPresentation* presentation = ite.First(); ite.IsNotComplete(); presentation = ite.Next())
- {
- count += presentation->CountFrame(ev);
- }
-
- return count;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::NewLinkManager
- //---------------------------------------------------------------------------------------
-
- FW_CLinkManager* FW_CPart::NewLinkManager(Environment *ev)
- {
- FW_UNUSED(ev);
- // Must be overridden if part creates Links
- return NULL;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::GetPartName
- //---------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPart::GetPartName(Environment *ev, FW_CString& partName) const
- {
- ODName* windowName = NULL;
- FW_Boolean nameIsProperty = FALSE;
-
- windowName = ODGetITextProp(ev, fODPart->GetStorageUnit(ev), kODPropName, kODMacIText, windowName);
- // windowName = ODGetPOName(ev, fODPart, NULL);
-
- if (windowName != NULL && GetITextStringLength(windowName) != 0)
- {
- partName = GetCStringFromIText(windowName);
- nameIsProperty = TRUE;
- }
- else
- partName = fPartUserName;
-
- if (windowName)
- DisposeIText(windowName);
-
- return nameIsProperty;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivEnableMenuBar
- //---------------------------------------------------------------------------------------
- // This is called when opening/closing a modal dialog.
- // We keep a count of nested modal dialogs so that we don't re-enable the menu-bar
- // if a modal dialog is still up
-
- void FW_CPart::PrivEnableMenuBar(Environment *ev, FW_Boolean enable, FW_Boolean appleMenu)
- {
- if (enable == false)
- fModalDialogCount += 1;
- else
- {
- fModalDialogCount -= 1;
- if (fModalDialogCount > 0) return;
- }
-
- #ifdef FW_BUILD_MAC
- GetMenuBar(ev)->MacEnableMenuBar(ev, enable);
- // We keep the Apple menu enabled for moveable dialog boxes
- if (enable == false && appleMenu == true)
- GetMenuBar(ev)->EnableCommand(ev, kODCommandAppleMenu, true);
- #endif
-
- #ifdef FW_BUILD_WIN
- // Windows does this automatically?
- #endif
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::InstallMenus
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::InstallMenus(Environment *ev, FW_CMenuBar* menuBar)
- {
- if (menuBar)
- menuBar->PrivDisplay(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::Changed
- //---------------------------------------------------------------------------------------
- // ODF API
-
- void FW_CPart::Changed(Environment *ev)
- {
- GetDraft(ev)->SetChangedFromPrev(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivGetPresentation
- //---------------------------------------------------------------------------------------
-
- FW_CPresentation* FW_CPart::PrivGetPresentation(Environment *ev, ODFrame* odFrame) const
- {
- ODTypeToken presDefault = GetSession(ev)->Tokenize(ev, kODPresDefault);
- ODTypeToken token = presDefault;
- FW_Boolean isRoot = TRUE;
-
- FW_CPresentation* presentation = NULL;
-
- if (odFrame != NULL)
- {
- token = odFrame->GetPresentation(ev);
- isRoot = odFrame->IsRoot(ev);
- }
-
- if (token == presDefault)
- presentation = fDefaultPresentation;
- else
- {
- presentation = FindPresentation(ev, token);
-
- if (presentation == NULL)
- presentation = fDefaultPresentation;
- }
-
- return ValidatePresentation(ev, presentation, isRoot);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::ValidatePresentation
- //---------------------------------------------------------------------------------------
-
- FW_CPresentation* FW_CPart::ValidatePresentation(Environment *ev, FW_CPresentation *presentation, FW_Boolean isRootFrame) const
- {
- FW_UNUSED(ev);
- FW_UNUSED(isRootFrame);
-
- return presentation;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::HasSelectionFocus
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPart::HasSelectionFocus(Environment *ev) const
- {
- if (fLastActiveFrame)
- {
- return fLastActiveFrame->HasSelectionFocus(ev);
- }
- else
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::GetActiveFacet
- //----------------------------------------------------------------------------------------
-
- ODFacet* FW_CPart::GetActiveFacet(Environment *ev) const
- {
- return (fLastActiveFrame != NULL) ? fLastActiveFrame->GetActiveFacet(ev) : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::GetSession
- //----------------------------------------------------------------------------------------
-
- ODSession* FW_CPart::GetSession(Environment *ev) const
- {
- return this->GetStorageUnit(ev)->GetSession(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::Release
- //----------------------------------------------------------------------------------------
- // Call inherited first when overridden
-
- void FW_CPart::Release(Environment *ev)
- {
- unsigned long refcount = fODPart->GetRefCount(ev);
-
- // ------ The last refcount is caused by the register idle -----
- if (refcount == 1 && fIdler != NULL)
- {
- FW_ASSERT(fIdleCount == 1); // We should only have the part register by now
- fIdler->UnregisterIdle(ev);
- }
-
- if (refcount == 0)
- {
- GetDraft(ev)->ReleasePart(ev, fODPart);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::ReleaseAll
- //----------------------------------------------------------------------------------------
- // Call inherited first when overridden
-
- void FW_CPart::ReleaseAll(Environment *ev)
- {
- // Will resolve or just delete my promises
- fDataInterchange->ResolveAllPromises(ev);
-
- // ----- Release part content
- if (fContent)
- fContent->ReleaseAll(ev);
-
- // ----- Delete any and all links
- if (fLinkManager)
- fLinkManager->RemoveAllLinks(ev);
-
- // ----- Release all display Frames
- FW_CPartPresentationIterator ite(this);
- for (FW_CPresentation* presentation = ite.First(); ite.IsNotComplete(); presentation = ite.Next())
- {
- presentation->ReleaseAll(ev);
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::IsReadOnly
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPart::IsReadOnly(Environment *ev) const
- {
- return GetDraft(ev)->GetPermissions(ev) < kODDPSharedWrite;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::GetDraft
- //----------------------------------------------------------------------------------------
-
- ODDraft* FW_CPart::GetDraft(Environment *ev) const
- {
- return fODPart->GetStorageUnit(ev)->GetDraft(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::HandleAdjustMenus
- //----------------------------------------------------------------------------------------
- // The part should have the last word in case it is readonly
-
- FW_Boolean FW_CPart::HandleAdjustMenus(Environment *ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- FW_Boolean result = FW_MEventHandler::HandleAdjustMenus(ev, menuBar, hasMenuFocus, isRoot);
-
- // ------ Disable items we know have to be disabled -----
- if (hasMenuFocus)
- {
- if (IsReadOnly(ev))
- {
- menuBar->EnableCommand(ev, kODCommandPaste, FALSE);
- menuBar->EnableCommand(ev, kODCommandCut, FALSE);
- menuBar->EnableCommand(ev, kODCommandClear, FALSE);
- menuBar->EnableCommand(ev, kODCommandPasteAs, FALSE);
- }
- #ifdef FW_BUILD_MAC
- // Set the name in the about item
- FW_CString aboutString;
- ::FW_PrivLoadODFString(ev, FW_kAboutString, aboutString);
- aboutString += fPartUserName;
- aboutString += "…";
- menuBar->SetItemString(ev, kODCommandAbout, aboutString);
- #endif
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::NewDocumentWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow* FW_CPart::NewDocumentWindow(Environment* ev)
- {
- FW_CRect windRect;
- ::FW_GetMainScreenBounds(windRect);
-
- FW_CPresentation* presentation = PrivGetPresentation(ev, NULL); // NULL means root frame
-
- return new FW_CWindow(ev,
- this,
- FW_CPart::gViewAsFrameToken,
- presentation,
- windRect.Size(), // I know it is too big but FW_CWindow::__ct will adjust it,
- windRect.TopLeft(),
- FW_kDocumentWindow);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPart::PrivCountIdleRegistering
- //----------------------------------------------------------------------------------------
-
- void FW_CPart::PrivCountIdleRegistering(FW_Boolean registering)
- {
- if (registering)
- fIdleCount++;
- else
- {
- FW_ASSERT(fIdleCount >= 1);
- fIdleCount--;
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::IsValidDisplayFrame
- //---------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPart::IsValidDisplayFrame(Environment* ev, ODStorageUnitID displayFrameID) const
- {
- FW_CPartFrameIterator ite(ev, this);
- for (FW_CFrame* frame = ite.First(ev); ite.IsNotComplete(ev); frame = ite.Next(ev))
- {
- if (frame->GetID(ev) == displayFrameID)
- return TRUE;
- }
-
- return FALSE;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivNewDataInterchange
- //---------------------------------------------------------------------------------------
-
- FW_CDataInterchange* FW_CPart::PrivNewDataInterchange(Environment* ev)
- {
- return new FW_CDataInterchange(ev, this);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::LinkStatusChanged
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::LinkStatusChanged(Environment *ev, ODFrame* odFrame)
- {
- FW_UNUSED(ev);
- FW_UNUSED(odFrame);
- // Nothing to do. See FW_CEmbeddingPart::LinkStatusChanged
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::Purge
- //---------------------------------------------------------------------------------------
-
- ODSize FW_CPart::Purge(Environment *ev, ODSize size)
- {
- FW_UNUSED(ev);
- FW_UNUSED(size);
- return 0;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::SetPrintInfo
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::SetPrintInfo(FW_CPrintInfo* printInfo)
- {
- fPrintInfo = printInfo;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::GetPrintInfo
- //---------------------------------------------------------------------------------------
-
- FW_CPrintInfo* FW_CPart::GetPrintInfo() const
- {
- return fPrintInfo;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::TranslateData
- //---------------------------------------------------------------------------------------
-
- ODTranslateResult FW_CPart::TranslateData(Environment* ev, ODStorageUnit* storageUnit,
- ODType translateKind,
- ODType desiredKind)
- {
- // Translation was requested from translateKind to desiredKind
-
- //--- Add desiredKind and create the destination storage unit view
- ODSUForceFocus(ev, storageUnit, kODPropContents, desiredKind);
- FW_CAcquireODStorageUnitView toView(ev, storageUnit);
-
- //--- Create the source storage unit view
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, translateKind, 0, kODPosUndefined);
- FW_CAcquireODStorageUnitView fromView(ev, storageUnit);
-
- //--- Get the translation object and perform the translation
- ODTranslation* translation = this->GetSession(ev)->GetTranslation(ev);
- ODTranslateResult translateResult = translation->TranslateView(ev, fromView, toView);
-
- return translateResult;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivAddPresentation
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::PrivAddPresentation(FW_CPresentation* presentation)
- {
- fPresentations->AddLast(presentation);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CPart::PrivRemovePresentation
- //---------------------------------------------------------------------------------------
-
- void FW_CPart::PrivRemovePresentation(FW_CPresentation* presentation)
- {
- fPresentations->Remove(presentation);
- }